<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
</head>

<body>
</body>

</html>
<!DOCTYPE html>
<html>

<head>
  <title>首页</title>
  <meta charset="utf-8">

  <style type="text/css">
    .hello {
      color: #428bca;
    }
  </style>
</head>

<body>
  <h3>这是index页面</h3>

  <span class="hello">你可以点击这里</span>
  <button>登录</button>



</body>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
<script type="text/javascript">
  var token = ''
  $('button').on('click', function () {
    $.ajax({
      type: 'post',
      url: '/api/login',
      data: { name: 'admin', pass: '123456' },
      success: function (data) {
        console.log(data);
        token = data.token
      },
      error: function (data) {
        console.log(data);
      }
   })
  })

  $('.hello').on('click', function () {
    $.ajax({
      type: 'get',
      url: '/api/hello',
      headers: { authorization: token },
      success: function (data) {
        console.log(data);
      },
      error: function (data) {
        console.log(data);
      }

    })
  })

</script>

</html>